﻿using Prism.Commands;
using Prism.Mvvm;
using Prism.Services.Dialogs;
using System;
using System.Collections.Generic;
using System.Linq;
using corpus_platform.Services;
using System.Collections.ObjectModel;
using Prism.Events;

namespace corpus_platform.ViewModels
{
    public class OntologyEditerViewModel : BindableBase, IDialogAware
    {
        public OntologyEditerViewModel()
        {

        }

        //private OntologyManager ontologyManager;
        private IEventAggregator eventAggregator;

        private string title = "新建本体";
        public string Title
        {
            get { return title; }
            set { SetProperty(ref title, value); }
        }

        private ObservableCollection<OntologyViewModel> displayedOntologies = new();
        public ObservableCollection<OntologyViewModel> DisplayedOntologies
        {
            get { return displayedOntologies; }
            set { SetProperty(ref displayedOntologies, value); }
        }

        private OntologyViewModel selectedOntology;
        public OntologyViewModel SelectedOntology
        {
            get { return selectedOntology; }
            set { SetProperty(ref selectedOntology, value); }
        }

        private bool isLocked = false;
        public bool IsLocked
        {
            get { return isLocked; }
            set { SetProperty(ref isLocked, value); }
        }

        private string informationText = "";
        public string InformationText
        {
            get { return informationText; }
            set { SetProperty(ref informationText, value); }
        }

        private string searchTerm = "";
        public string SearchTerm
        {
            get { return searchTerm; }
            set { SetProperty(ref searchTerm, value); }
        }

        public event Action<IDialogResult> RequestClose;

        public bool CanCloseDialog()
        {
            return true;
        }

        public void OnDialogClosed()
        {
        }

        public void OnDialogOpened(IDialogParameters parameters)
        {
            string mode = parameters.GetValue<string>("mode");
            //ontologyManager = parameters.GetValue<OntologyManager>("ontologyManager");
            eventAggregator = parameters.GetValue<IEventAggregator>("eventAggregator");
        }

        private DelegateCommand commandSearchClass;
        public DelegateCommand CommandSearchClass =>
            commandSearchClass ?? (commandSearchClass = new DelegateCommand(ExecuteCommandSearchClass));

        void ExecuteCommandSearchClass()
        {

        }


        private DelegateCommand commandLockSelectedOntology;
        public DelegateCommand CommandLockSelectedOntology =>
            commandLockSelectedOntology ?? (commandLockSelectedOntology = new DelegateCommand(ExecuteCommandLockSelectedOntology));

        void ExecuteCommandLockSelectedOntology()
        {
            IsLocked = !IsLocked;
        }


        private DelegateCommand commandCancel;
        public DelegateCommand CommandCancel =>
            commandCancel ?? (commandCancel = new DelegateCommand(ExecuteCommandCancel));

        void ExecuteCommandCancel()
        {
            RequestClose.Invoke(new DialogResult());
        }
    }
}
